package co.yixiang.yshop.module.product.dal.mysql.storeproductstockwarning;

import java.util.*;

import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
import co.yixiang.yshop.module.product.dal.dataobject.storeproduct.StoreProductDO;
import co.yixiang.yshop.module.product.dal.dataobject.storeproductstockwarning.StoreProductStockWarningDO;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
import co.yixiang.yshop.module.product.controller.admin.storeproductstockwarning.vo.*;

/**
 * 商品库存预警 Mapper
 *
 * @author admin
 */
@Mapper
public interface StoreProductStockWarningMapper extends BaseMapperX<StoreProductStockWarningDO> {

    default PageResult<StoreProductStockWarningRespVO> selectPage(StoreProductStockWarningPageReqVO reqVO) {
        return selectJoinPage(reqVO,StoreProductStockWarningRespVO.class, new MPJLambdaWrapper<StoreProductStockWarningDO>()
                .selectAll(StoreProductStockWarningDO.class)
                .selectAs(StoreProductDO::getStoreName,StoreProductStockWarningRespVO::getProductName)
                .selectAs(StoreProductDO::getImage,StoreProductStockWarningRespVO::getProductImage)
                .leftJoin(StoreProductDO.class,StoreProductDO::getId,StoreProductStockWarningDO::getGoodsId)
                .eq(reqVO.getType() == 2,StoreProductStockWarningDO::getStock,0)
        );
//        return selectPage(reqVO, new LambdaQueryWrapperX<StoreProductStockWarningDO>()
//                .eqIfPresent(StoreProductStockWarningDO::getGoodsId, reqVO.getGoodsId())
//                .eqIfPresent(StoreProductStockWarningDO::getGoodsSkuId, reqVO.getGoodsSkuId())
//                .eqIfPresent(StoreProductStockWarningDO::getGoodsSkuText, reqVO.getGoodsSkuText())
//                .eqIfPresent(StoreProductStockWarningDO::getStockWarning, reqVO.getStockWarning())
//                .betweenIfPresent(StoreProductStockWarningDO::getCreateTime, reqVO.getCreateTime())
//                .orderByDesc(StoreProductStockWarningDO::getId));
    }

    default List<StoreProductStockWarningDO> selectList(StoreProductStockWarningExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<StoreProductStockWarningDO>()
                .eqIfPresent(StoreProductStockWarningDO::getGoodsId, reqVO.getGoodsId())
                .eqIfPresent(StoreProductStockWarningDO::getGoodsSkuId, reqVO.getGoodsSkuId())
                .eqIfPresent(StoreProductStockWarningDO::getGoodsSkuText, reqVO.getGoodsSkuText())
                .eqIfPresent(StoreProductStockWarningDO::getStockWarning, reqVO.getStockWarning())
                .betweenIfPresent(StoreProductStockWarningDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StoreProductStockWarningDO::getId));
    }

}
